package com.lzx.study.Controller;

import com.lzx.study.records.StudentRecord;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.Map;
import java.util.function.Consumer;

@RestController
public class StructuredOutputController {
    @Resource(name = "qwenChatClient")
    private ChatClient qwenChatClient;

    @GetMapping("/structuredOutput/chat")
    public StudentRecord chat(@RequestParam(name = "sname") String sname,
                              @RequestParam(name = "email") String email) {
        StudentRecord studentRecord = qwenChatClient.prompt().user(new Consumer<ChatClient.PromptUserSpec>() {
            @Override
            public void accept(ChatClient.PromptUserSpec promptUserSpec) {
                promptUserSpec.text("学号1001，我叫{sname},大学专业软件工程，邮箱{email}")
                        .params(Map.of("sname", sname, "email", email));
            }
        }).call().entity(StudentRecord.class);
        System.out.println("content = " + studentRecord);
        return studentRecord;
    }
    @GetMapping("/structuredOutput/chat2")
    public StudentRecord cha2(@RequestParam(name = "sname") String sname,
                              @RequestParam(name = "email") String email) {
        String stringTemplate = """
                学号1001，我叫{sname},大学专业计算机，邮箱{email}   
                """;
        StudentRecord studentRecord = qwenChatClient.prompt().user(promp -> promp.text(stringTemplate).params(Map.of("sname", sname, "email", email)))
                .call().entity(StudentRecord.class);
        System.out.println("content = " + studentRecord);
        return studentRecord;
    }
}
